package com.gqb.jvm;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;


public class ProperiesUtils {
	public static String getProperty(String key){
		Properties prop=new Properties();
		String value=null;
		try {
			 InputStream in = ProperiesUtils.class.getClassLoader().getResourceAsStream("config.properties");
	            prop.load(in);     ///加载属性列表
	            Iterator<String> it=prop.stringPropertyNames().iterator();
	            while(it.hasNext()){
	            	if(key.equals(it.next())){
	            		value= prop.getProperty(key,"0");
	            	}
	            }
	            in.close();
	            return value;
		} catch (Exception e) {
			e.printStackTrace();
			return value;
		}
	}
	
	public static boolean setProperty(String key ,String value){
		Properties properties=new Properties();
		InputStream in=ProperiesUtils.class.getClassLoader().getResourceAsStream("config.properties");
		try {
			properties.load(in);
			Iterator<String> it=properties.stringPropertyNames().iterator();
			while (it.hasNext()) {
				if(key.equals(it.next())){
					properties.setProperty(key, value);
					return true;
				}
				
			}
			return false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}
}